#-*- encoding=UTF-8 -*-

'''
演示：
    清理画布的方法
'''

import tkinter as tk

def clearAll():
    canvas.delete(tk.ALL)

def clearXX():
    canvas.delete(c3)

def delC():
    canvas.destroy()

win = tk.Tk()
win.geometry('400x400')

canvas = tk.Canvas(win, height=200, width=200, bg='white')
canvas.create_line(0, 100, 200, 100) # 直线
canvas.create_line(100, 0, 100, 200,fill='red') # 红色直线
c3 = canvas.create_line(50, 0, 50, 200, dash=(4,4), fill='green') # 绿色虚线

canvas.pack()

# 方法1
btn1 = tk.Button(win, text='全部清理1', command=(lambda x=tk.ALL: canvas.delete(x)))
btn1.pack()

# 方法2
btn2 = tk.Button(win, text='全部清理2', command=clearAll)
btn2.pack()

# 方法3
btn3 = tk.Button(win, text='清理绿色虚线', command=clearXX)
btn3.pack()

# 方法4
btn4 = tk.Button(win, text='删除画布', command=delC)
btn4.pack()

win.mainloop()
